package weaver.interfaces.holyview.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 公告发布流程
 * @ModifyLog:
 **/
/*
 *@Description: 会议通知回执流程提交后更新会议表
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaMeetingNoticeReceiptAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        //主表
        String tablename = requestInfo.getRequestManager().getBillTableName();
        baseBean.writeLog( "------WeaMeetingNoticeReceiptAction-------" + requestid );
        try {
            String sql = "select meetingid,attendHrm,isattend from " + tablename + " where requestid=?";
            rs.executeQuery( sql, requestid );
            rs.next();
            //会议Id
            String meetingid = Util.null2String( rs.getString( "meetingid" ) );
            //参会人员
            String attendHrm = Util.null2String( rs.getString( "attendHrm" ) );
            //是否参加
            String isattend = Util.null2String( rs.getString( "isattend" ) );
            if ("2".equals( isattend )) {
                rs.executeQuery( "select totalmember,hrmmembers from meeting where id=?", meetingid );
                rs.next();
                //参会人数
                int totalmember = Util.getIntValue( rs.getString( "totalmember" ) );
                //参会人
                String hrmmembers = Util.null2String( rs.getString( "hrmmembers" ) );
                String newhrmmembers =  getHrmmembers(hrmmembers,attendHrm);
                int newtotalmember = totalmember-1;
                rs.executeUpdate( "update meeting set totalmember=?,hrmmembers=? where id=?",
                        new Object[]{newtotalmember,newhrmmembers,meetingid} );
                //rs.executeUpdate( "delete meeting_member2  where meetingid=?", meetingid);
                rs.executeUpdate( "delete Meeting_ShareDetail where meetingid=? and userid=?", new Object[]{meetingid,attendHrm} );
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

    public static String getHrmmembers(String hrmmembers,String attendHrm) {
        String newhrmmembers = "";
        String [] strs = hrmmembers.split(",");
        for(String str:strs){
            if(!str.equals(attendHrm)){
                newhrmmembers +="".equals(newhrmmembers)?str:","+str;
            }
        }
        return newhrmmembers;
    }
}
